package com.entity;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * A data access object (DAO) providing persistence and search support for Ryzl
 * entities. Transaction control of the save(), update() and delete() operations
 * can directly support Spring container-managed transactions or they can be
 * augmented to handle user-managed Spring transactions. Each of these methods
 * provides additional information for how to configure it for the desired type
 * of transaction control.
 * 
 * @see com.entity.Ryzl
 * @author MyEclipse Persistence Tools
 */

public class RyzlDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(RyzlDAO.class);
	// property constants
	public static final String XM = "xm";
	public static final String FJ = "fj";
	public static final String BH = "bh";
	public static final String XB = "xb";
	public static final String ZP = "zp";
	public static final String GWDJ = "gwdj";
	public static final String CSRQ = "csrq";
	public static final String CJGZRQ = "cjgzrq";
	public static final String CJJSGZRQ = "cjjsgzrq";
	public static final String HYZK = "hyzk";
	public static final String ZZMM = "zzmm";
	public static final String MZ = "mz";
	public static final String JG = "jg";
	public static final String XL = "xl";
	public static final String ZY = "zy";
	public static final String BYYX = "byyx";
	public static final String LXDZ = "lxdz";
	public static final String SFZH = "sfzh";
	public static final String LXDH = "lxdh";
	public static final String JBGZ = "jbgz";
	public static final String RYSX = "rysx";
	public static final String HTQX = "htqx";
	public static final String GRJL = "grjl";
	public static final String BZ = "bz";
	public static final String LZSJ = "lzsj";
	public static final String GZZT = "gzzt";
	public static final String HTQX2 = "htqx2";
	public static final String USER_PIC = "userPic";
	public static final String ADD_TIME = "addTime";
	public static final String FGFNS="fgfns";

	protected void initDao() {
		// do nothing
	}

	public void save(Ryzl transientInstance) {
		log.debug("saving Ryzl instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Ryzl persistentInstance) {
		log.debug("deleting Ryzl instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Ryzl findById(java.lang.Integer id) {
		log.debug("getting Ryzl instance with id: " + id);
		try {
			Ryzl instance = (Ryzl) getHibernateTemplate().get(
					"com.entity.Ryzl", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Ryzl instance) {
		log.debug("finding Ryzl instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Ryzl instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Ryzl as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByXm(Object xm) {
		return findByProperty(XM, xm);
	}
	public List findByFgfns(Object fgfns) {
		return findByProperty(FGFNS, fgfns);
	}

	public List findByGwdj(Object gwdj) {
		return findByProperty(GWDJ, gwdj);
	}
	
	public List findByFj(Object fj) {
		return findByProperty(FJ, fj);
	}
	
	public List findByBh(Object bh) {
		return findByProperty(BH, bh);
	}

	public List findByXb(Object xb) {
		return findByProperty(XB, xb);
	}

	public List findByZp(Object zp) {
		return findByProperty(ZP, zp);
	}

	public List findByCsrq(Object csrq) {
		return findByProperty(CSRQ, csrq);
	}

	public List findByCjgzrq(Object cjgzrq) {
		return findByProperty(CJGZRQ, cjgzrq);
	}

	public List findByCjjsgzrq(Object cjjsgzrq) {
		return findByProperty(CJJSGZRQ, cjjsgzrq);
	}

	public List findByHyzk(Object hyzk) {
		return findByProperty(HYZK, hyzk);
	}

	public List findByZzmm(Object zzmm) {
		return findByProperty(ZZMM, zzmm);
	}

	public List findByMz(Object mz) {
		return findByProperty(MZ, mz);
	}

	public List findByJg(Object jg) {
		return findByProperty(JG, jg);
	}

	public List findByXl(Object xl) {
		return findByProperty(XL, xl);
	}

	public List findByZy(Object zy) {
		return findByProperty(ZY, zy);
	}

	public List findByByyx(Object byyx) {
		return findByProperty(BYYX, byyx);
	}

	public List findByLxdz(Object lxdz) {
		return findByProperty(LXDZ, lxdz);
	}

	public List findBySfzh(Object sfzh) {
		return findByProperty(SFZH, sfzh);
	}

	public List findByLxdh(Object lxdh) {
		return findByProperty(LXDH, lxdh);
	}

	public List findByJbgz(Object jbgz) {
		return findByProperty(JBGZ, jbgz);
	}

	public List findByRysx(Object rysx) {
		return findByProperty(RYSX, rysx);
	}

	public List findByHtqx(Object htqx) {
		return findByProperty(HTQX, htqx);
	}

	public List findByGrjl(Object grjl) {
		return findByProperty(GRJL, grjl);
	}

	public List findByBz(Object bz) {
		return findByProperty(BZ, bz);
	}

	public List findByLzsj(Object lzsj) {
		return findByProperty(LZSJ, lzsj);
	}

	public List findByGzzt(Object gzzt) {
		return findByProperty(GZZT, gzzt);
	}

	public List findByHtqx2(Object htqx2) {
		return findByProperty(HTQX2, htqx2);
	}

	public List findByUserPic(Object userPic) {
		return findByProperty(USER_PIC, userPic);
	}

	public List findByAddTime(Object addTime) {
		return findByProperty(ADD_TIME, addTime);
	}

	public List findAll() {
		log.debug("finding all Ryzl instances");
		try {
			String queryString = "from Ryzl order by bh asc";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Ryzl merge(Ryzl detachedInstance) {
		log.debug("merging Ryzl instance");
		try {
			Ryzl result = (Ryzl) getHibernateTemplate().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Ryzl instance) {
		log.debug("attaching dirty Ryzl instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Ryzl instance) {
		log.debug("attaching clean Ryzl instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static RyzlDAO getFromApplicationContext(ApplicationContext ctx) {
		return (RyzlDAO) ctx.getBean("RyzlDAO");
	}
	public int getCount(String sql){
		int aid=0;
		List list=getHibernateTemplate().find(sql);
		if(list!=null&&list.size()>0){
			if(list.get(0)!=null){
				aid=Double.valueOf(list.get(0).toString()).intValue();
				return Double.valueOf(list.get(0).toString()).intValue();
			}else{
				return 0;
			}
		}else{
			return 0;
		}
	}
	
	public List gethql(String hql)
	{
		Session session = this.getSession();
		session.beginTransaction();
		List list = null;
		try {
			session.beginTransaction().begin();
			Query query = session.createQuery(hql);
			list = query.list();
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally{
			session.close();
		}
		return list;
		
	}
	
	
}